<?
	$cCorte = getParam('corte');
	$oModPortal =& loadModule('portal');
	$cUrlBase= $oModPortal->aDatos[armador][cUrlBase];
	switch( $nOpcion)
	{
		case 3: // Listado cerrado
			echo "	<div class='titulo_filtro'>
						<div style='float:left;'><a href='javascript://void(0);' onclick='send( \"$cUrlBase&amp;rf=action&amp;op=1&amp;corte=$cCorte\", refreshElement, \"divFiltro_$cCorte\");'><img src='imagenes/ico_filtro_mas.gif' width='9' height='9' style='border: none' alt='+' />&nbsp;</a></div>
						<div style='float:left'>" . $oModPortal->aDatos[armador][aCortes][$cCorte][cTitulo] . "</div>
					</div>";
			break;		
		case 1: // Listado abierto
			$cValor = getParam($cCorte);
			$cTitulo = $oModPortal->aDatos[armador][aCortes][$cCorte][cTitulo];
			if ( $cValor ) $cTitulo  .= " (" . (1+ substr_count($cValor,',') ) . ")";
			echo "	<div class='titulo_filtro'>
						<div style='float:left;'><a href='javascript://void(0);' onclick='send( \"$cUrlBase&amp;rf=action&amp;op=3&amp;corte=$cCorte\", refreshElement, \"divFiltro_$cCorte\");'><img src='imagenes/ico_filtro_menos.gif' width='9' height='9' style='border: none' alt='-' />&nbsp;</a></div>
						<div style='float:left'>" . $cTitulo . "</div>
					</div>";
			$cSql = $oModPortal->aDatos[armador][aCortes][$cCorte][cSql];
			$nqCorte = $this->oDatabase->total($cSql);
			$cSql .= " ORDER BY "  . ($oModPortal->aDatos[armador][aCortes][$cCorte][cOrder] ? $oModPortal->aDatos[armador][aCortes][$cCorte][cOrder] : " cant DESC");
			if ( $nqCorte < 10 ) 
				$aMatrix = $this->oDatabase->getMatrix( $cSql );
			else
				$aMatrix = $this->oDatabase->getMatrix( $cSql , 0, 5);
				
			echo "<ul class='filtro_ul'>";
			foreach ( $aMatrix as $aRow )
			{
				//$cItem  = strFit(extractLanguage($aRow[item]) , 15 ) ;
				$cItem  = extractLanguage($aRow[item]) ;
				$cUrl = $cUrlBase . "&amp;$cCorte=" .($cValor ? $cValor . "," . $aRow[id] : $aRow[id]);
				echo "<li><input class='check' type='checkbox' onclick='document.location.href=\"" . $cUrl ."\";' />$cItem ($aRow[cant])</li>";
				//echo "<li><a href='$cUrlBase&amp;$cCorte=" .($cValor ? $cValor . "," . $aRow[id] : $aRow[id]) . "'>$cItem</a> ($aRow[cant])</li>";
			}
			if ( $nqCorte >= 10 )
			{
				echo "<li><a class='mas' href='javascript://void(0);' onclick='openPopup( \"$cUrlBase&amp;rf=action&amp;op=2&amp;corte=$cCorte\", \"\", 600, 550 );' >" . mostrar_termino(LBL_Ver_Todos) ."</a></li>";
			}
			echo "</ul>";
		break;
		case 2: // PopUp
			echo "<div id='filtros_popup'>";
				echo "<h2>" . mostrar_termino('LBL_TodosLos'.$oModPortal->aDatos[armador][aCortes][$cCorte][cTitulo]) . "</h2>";
				//
				$cValor = getParam($cCorte);
				$cUrlCorte  = $cUrlBase;
				$nPosDesde = strpos( '&amp;' . $cUrlBase, "&amp;$cCorte=" );
				if ( !$nPosDesde === false ) // Si lo encontro => quita
				{ 
					$nPosHasta = strpos( '&amp;' . $cUrlBase, '&amp;' , $nPosDesde + 6 + strlen($cCorte) );
					$cUrlCorte  = substr($cUrlBase, 0, $nPosDesde );
					if ( $nPosHasta ) $cUrlCorte  .=  substr($cUrlBase, $nPosHasta );
				}
				$cSql = $oModPortal->aDatos[armador][aCortes][$cCorte][cSql];
				$nqCorte = $this->oDatabase->total($cSql);
				$nqMitad = $nqCorte / 2;
				$nqMitad--;
				$cSql .= " ORDER BY 2 ASC";
				$aMatrix = $this->oDatabase->getMatrix( $cSql );
				echo "<form name='frmCorte' id='frmCorte' >";
				
				echo "<div style='overflow:auto; margin-top:10px;'>";
					echo "<div style='float:left'>";
						echo "<ul class='filtro_ul'>";
						for ( $i = 0; $i <= $nqMitad; $i++ )
						{
							$cItem  = extractLanguage($aMatrix[$i][item]) ;
							echo "<li><input class='check' type='checkbox'  name='checkCorte[]' value='" . $aMatrix[$i][id] . "'  />$cItem (".$aMatrix[$i][cant].")</li>";
						}
						echo "</ul>";
					echo "</div>";
					echo "<div style='float:right'>";
						echo "<ul class='filtro_ul'>";
						for ( $i = $nqMitad + 1; $i < $nqCorte; $i++ )
						{
							$cItem  = extractLanguage($aMatrix[$i][item]) ;
							echo "<li><input class='check' type='checkbox' name='checkCorte[]' value='" . $aMatrix[$i][id] . "' />$cItem (".$aMatrix[$i][cant].")</li>";
						}
						echo "</ul>";
					echo "</div>";
				echo "</div>";
			echo "</form>";
			$cUrl = "$cUrlCorte&amp;$cCorte=";
			if ($cValor ) $cUrl .= $cValor. ","; 
			echo "	<div style='overflow:auto; margin:20px auto; width:200px'>
						<div class='div_boton90' style='float:left;'><a style='color:#ffffff;' href='javascript://void(0);' onclick=\"f=document.getElementById('frmCorte');s='';for(var i=0;i<f.length;i++) if (f[i].name=='checkCorte[]' && f[i].checked) {s=s+(s==''?'':',')+f[i].value;} if( s != '' ) document.location.href = '$cUrl' + s;\";closePopup();return false;\">".mostrar_termino( 'LBL_Aceptar' )."</a></div>
						<div class='div_boton_cancelar' style='float:right;'><a style='color:#ffffff;' href='javascript://void(0);' onclick='closePopup();return false;' >".mostrar_termino( 'LBL_Cancelar' )."</a></div>
					</div>";
			echo "</div>";
		break;
		default: // es filtro con todos los cortes
?>
<div id="filtros">
	<!-- Variables -->
	<div style="margin-top: 10px">
		<div class="subtitulo"><?=mostrar_termino('LBL_Seleccionar')?></div>
		<div style="overflow:auto; height:30px;">
			<form onsubmit="o=document.getElementById('buscar');document.location.href='<?=$cUrlBase?>&amp;&amp;buscar=' + o.value;return false;" >
			<div style="float:left"><input type='text' class='text' id='buscar' name='buscar' value="<?=$oModPortal->aDatos[armador][buscar]?>" /></div>
			<div style="float:left; padding:4px 0 0 2px;">
				<input type='image' src="imagenes/buscar.gif" style="border:none;width:13px;height:12px;" alt=">" />
			</div>
			</form>
		</div>
		<div>
	<?
		foreach( $oModPortal->aDatos[armador][aCortes] as $cCorte => $aCorte )
		{
			$cValor = getParam($cCorte);
			// Si el corte es maestro o es un corte simple y tiene un valor => no aparece
			if ( $oModPortal->aDatos[armador][aCortes][$cCorte][nTipo] != 1 || !$cValor ) 
			{
				$cSql = $aCorte[cSql];
				$nqCorte = $this->oDatabase->total($cSql);
				if ( $nqCorte  > 0 || 1) 
				{
					echo "<div id='divFiltro_$cCorte' style='margin-top:5px;'>";
					if ( $aCorte[bAbierto] )
					{
						$cTitulo = $aCorte[cTitulo];
						if ( $cValor ) $cTitulo  .= " (" . (1+ substr_count($cValor,',') ) . ")";
						echo "	<div class='titulo_filtro'>
									<div style='float:left'><a href='javascript://void(0);' onclick='send( \"$cUrlBase&amp;rf=action&amp;op=3&amp;corte=$cCorte\", refreshElement, \"divFiltro_$cCorte\");'><img src='imagenes/ico_filtro_menos.gif' width='9' height='9' style='border: none' alt='-' />&nbsp;</a></div>
									<div style='float:left'>" . $cTitulo . "</div>
								</div>";
						$cSql .= " ORDER BY "  . ($oModPortal->aDatos[armador][aCortes][$cCorte][cOrder] ? $oModPortal->aDatos[armador][aCortes][$cCorte][cOrder] : " cant DESC");
						if ( $nqCorte < 10 ) 
							$aMatrix = $this->oDatabase->getMatrix( $cSql );
						else
							$aMatrix = $this->oDatabase->getMatrix( $cSql , 0, 5);	
						echo "<div>
								<ul class='filtro_ul'>";
						
						$cUrlCorte  = $cUrlBase;
						$nPosDesde = strpos( '&amp;' . $cUrlBase, "&amp;$cCorte=" );
						if ( !$nPosDesde === false ) // Si lo encontro => quita
						{ 
							$nPosHasta = strpos( '&amp;' . $cUrlBase, '&amp;' , $nPosDesde + 6 + strlen($cCorte) );
							$cUrlCorte  = substr($cUrlBase, 0, $nPosDesde );
							if ( $nPosHasta ) $cUrlCorte  .=  substr($cUrlBase, $nPosHasta );
						}
						foreach ( $aMatrix as $aRow )
						{
							//$cItem  = strFit(extractLanguage($aRow[item]) , 15 ) ;
							$cItem  = extractLanguage($aRow[item]) ;
							$cUrl = $cUrlCorte . "&amp;$cCorte=" .($cValor ? $cValor . "," . $aRow[id] : $aRow[id]);
							echo "<li><input class='check' type='checkbox' onclick='document.location.href=\"" . $cUrl ."\";' />$cItem ($aRow[cant])</li>";
						}
						if ( $nqCorte >= 10 )
						{
							echo "<li><a class='mas' href='javascript://void(0);' onclick='openPopup( \"$cUrlBase&amp;rf=action&amp;op=2&amp;corte=$cCorte\", \"\", 600, 550 );' >". mostrar_termino(LBL_Ver_Todos)."</a></li>";
						}
						echo "	</ul>
							</div>";
					} else 
					echo "	<div class='titulo_filtro' style='overflow:auto'>
								<div style='float:left;'><a href='javascript://void(0);' onclick='send( \"$cUrlBase&amp;rf=action&amp;op=1&amp;corte=$cCorte\", refreshElement, \"divFiltro_$cCorte\");'><img src='imagenes/ico_filtro_mas.gif' width='9' height='9' style='border: none' alt='+' />&nbsp;</a></div>
								<div style='float:left'>" . $aCorte[cTitulo] . "</div>
							</div>";
					echo "</div>";
				}
			}
		}
	?>
		</div>
	</div>
</div>
<?
	}
?>